from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from entity import Questnr,Option

engine = create_engine('mysql+pymysql://root:yebu666888@127.0.0.1/questionnaire_survey?charset=utf8')
DBSession = sessionmaker(bind=engine)


session = DBSession()
questnr = session.query(Questnr,Option).join(Option, Option.questnr_id == Questnr.questnr_id).filter(Questnr.questnr_id == 1).order_by(Option.option_sequence).all()
#.query(Questnr).join(Option) 这个写法是完整的 但是只select了Questnr表  所以改为:
#.query(Questnr,Option).join(Option)  这样就select 了 表 Questnr和Option
print(  questnr[0].Questnr.questnr_name, questnr[0].Option.option_name)

session.close()

